print dialog: Use headerbar
authorWilliam Jon McCann <william.jon.mccann@gmail.com>
Sun, 8 Dec 2013 14:38:43 +0000 (15:38 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 17 Jan 2014 22:52:08 +0000 (17:52 -0500)
Make the print dialog use a headerbar when desired.

https://bugzilla.gnome.org/show_bug.cgi?id=720059

gtk/gtkprintunixdialog.c
gtk/gtkprintunixdialog.ui
gtk/gtkprintunixdialog.ui.h

index 1bc7617268d915a53299b2d5a0cc301dc32fc19a..acbfc3c1c0b1059e4f313b5f1c0043ee101d5628 100644 (file)
@@ -55,6 +55,7 @@
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtkdialogprivate.h"
 
 
 /**
 #define RULER_RADIUS 2
 
 
+static GObject *gtk_print_unix_dialog_constructor  (GType               type,
+                                                    guint               n_params,
+                                                    GObjectConstructParam *params);
 static void     gtk_print_unix_dialog_destroy      (GtkPrintUnixDialog *dialog);
 static void     gtk_print_unix_dialog_finalize     (GObject            *object);
 static void     gtk_print_unix_dialog_set_property (GObject            *object,
@@ -307,7 +311,6 @@ struct GtkPrintUnixDialogPrivate
   GtkWidget *print_at_radio;
   GtkWidget *print_at_entry;
   GtkWidget *print_hold_radio;
-  GtkWidget *preview_button;
   GtkWidget *paper_size_combo;
   GtkWidget *paper_size_combo_label;
   GtkCellRenderer *paper_size_renderer;
@@ -401,6 +404,7 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
   object_class = (GObjectClass *) class;
   widget_class = (GtkWidgetClass *) class;
 
+  object_class->constructor = gtk_print_unix_dialog_constructor;
   object_class->finalize = gtk_print_unix_dialog_finalize;
   object_class->set_property = gtk_print_unix_dialog_set_property;
   object_class->get_property = gtk_print_unix_dialog_get_property;
@@ -514,7 +518,6 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
   gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, print_at_radio);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, print_at_entry);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, print_hold_radio);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, preview_button);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, paper_size_combo);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, paper_size_combo_label);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, paper_size_renderer);
@@ -743,6 +746,13 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
   priv->has_selection = FALSE;
 
   gtk_widget_init_template (GTK_WIDGET (dialog));
+  gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                          _("Pre_view"), GTK_RESPONSE_APPLY,
+                          _("_Cancel"), GTK_RESPONSE_CANCEL,
+                          _("_Print"), GTK_RESPONSE_OK,
+                          NULL);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
   /* Treeview auxilary functions need to be setup here  */
   gtk_tree_model_filter_set_visible_func (priv->printer_list_filter,
@@ -794,6 +804,32 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
   _gtk_print_load_custom_papers (priv->custom_paper_list);
 }
 
+static GObject *
+gtk_print_unix_dialog_constructor (GType                  type,
+                                   guint                  n_params,
+                                   GObjectConstructParam *params)
+{
+  GObject *object;
+  gboolean use_header;
+
+  object = G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->constructor (type, n_params, params);
+
+  g_object_get (object, "use-header-bar", &use_header, NULL);
+  if (use_header)
+    {
+       /* Reorder the preview button */
+       GtkWidget *button, *parent;
+       button = gtk_dialog_get_widget_for_response (GTK_DIALOG (object), GTK_RESPONSE_APPLY);
+       g_object_ref (button);
+       parent = gtk_widget_get_parent (button);
+       gtk_container_remove (GTK_CONTAINER (parent), button); 
+       gtk_header_bar_pack_end (GTK_HEADER_BAR (parent), button);
+       g_object_unref (button);
+    }
+
+  return object;
+}
+
 static void
 gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog)
 {
@@ -1612,6 +1648,7 @@ update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
   gboolean can_collate;
   const gchar *copies;
+  GtkWidget *button;
 
   copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin));
   can_collate = (*copies != '\0' && atoi (copies) > 1);
@@ -1632,10 +1669,8 @@ update_dialog_from_capabilities (GtkPrintUnixDialog *dialog)
   gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet),
                             caps & GTK_PRINT_CAPABILITY_NUMBER_UP);
 
-  if (caps & GTK_PRINT_CAPABILITY_PREVIEW)
-    gtk_widget_show (priv->preview_button);
-  else
-    gtk_widget_hide (priv->preview_button);
+  button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_APPLY);
+  gtk_widget_set_visible (button, (caps & GTK_PRINT_CAPABILITY_PREVIEW) != 0);
 
   update_collate_icon (NULL, dialog);
 
index 0a0530ab96425768c03a755269365514d8c6c5fc..3d2aec7d39c50f50baa01d29eb966f2b6c067921 100644 (file)
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="preview_button">
-                <property name="label" translatable="yes">Pre_view</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label" translatable="yes">_Cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="print_button">
-                <property name="label" translatable="yes">_Print</property>
-                <property name="visible">True</property>
-                <property name="sensitive">False</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
+        <property name="border_width">0</property>
         <child>
           <object class="GtkBox" id="box1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="border_width">5</property>
+            <property name="border_width">0</property>
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
     </child>
-    <action-widgets>
-      <action-widget response="-10">preview_button</action-widget>
-      <action-widget response="-6">cancel_button</action-widget>
-      <action-widget response="-5">print_button</action-widget>
-    </action-widgets>
   </template>
 </interface>
index a70fba7d4e2a75273e8c830e4d239ade3cc94785..7630dbe3d463437ee6ca3f5b61c298f7a279d438 100644 (file)
@@ -1,6 +1,3 @@
-N_("Pre_view");
-N_("_Cancel");
-N_("_Print");
 N_("Printer");
 
 /* this is the header for the location column in the print dialog */